package me.shurufa.fragments;

/**
 * @author andy
 * 懒加载 只为了一次延迟加载。晓得伐
 */
public abstract class BaseLazyListFragment extends BaseListFragment {
    protected boolean isVisible;
    protected boolean isExecuted;

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {//frahment从不可见到完全可见的时候，会调用该方法
        super.setUserVisibleHint(isVisibleToUser);
        if (getUserVisibleHint() && !isExecuted){
            isVisible = true;
            isExecuted = true;
            onVisible();
        }else {
            isVisible = false;
            onInvisible();
        }
    }

    protected abstract void lazyLoad();//懒加载的方法,在这个方法里面我们为Fragment的各个组件去添加数据

    protected void onVisible(){
        lazyLoad();
    }

    protected void onInvisible(){

    }
}
